package com.suapi.suapiinterface.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/other")
public class OtherAPIController {

    @GetMapping("/random/imageUrl")
    public String getRandomImageUrl() {
        HttpRequest request = HttpRequest.get("https://api.btstu.cn/sjbz/api.php?format=json");
        HttpResponse response = request.execute();
        if (response.isOk()) {
            String json = response.body();
            JSONObject jsonObject = JSONObject.parseObject(json);
            String imgUrl = jsonObject.get("imgurl").toString();
            return imgUrl;
        } else {
            throw new RuntimeException("获取随机图片失败");
        }
    }

}
